﻿package  
{
	
	import flash.display.MovieClip;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.events.MouseEvent;
	
	public class BattleResultUI extends MovieClip 
	{
		private var textArray:Array = null;
		private var timer:Timer = new Timer( 5000 );
		private var count:int = 0;
		
		private var itemObject:Object = null;
		
		public function BattleResultUI() 
		{
			// constructor code
			
			timer.addEventListener( TimerEvent.TIMER , onTimer );
			closeButton.addEventListener( MouseEvent.CLICK , onClose );
			
			this.x = 290;
			this.y = 120;
			
			textArray = new Array();
			textArray.push( t0 );
			textArray.push( t1 );
			textArray.push( t2 );
			textArray.push( t3 );
			textArray.push( t4 );
			textArray.push( t5 );
			
			for ( var i:int = 0 ; i < textArray.length ; i++ )
			{
				textArray[i].visible = false;
				textArray[i].levelUp.text = "LevelUp!"
				textArray[i].exp.text = "Exp"
			}
			
			itemObject = new Object();
		}
		
		private function onClose( e:MouseEvent ):void
		{
			timer.stop();
			this.visible = false;
		}
		
		private function onTimer( e:TimerEvent ):void
		{
			timer.stop();
			this.visible = false;
		}
		
		public function show():void
		{
			this.visible = true;
			timer.start();
		}
		
		public function clear():void
		{
			count = 0;
			
			for ( var i:int = 0 ; i < textArray.length ; i++ )
			{
				textArray[i].visible = false;
			}
			
			itemText.visible = false;
			
			for ( var key:Object in itemObject )
			{
				itemObject[ key ] = null;
				delete itemObject[ key ];
			}
		}
		
		public function addText( n:String , e:int , l:Boolean ):void
		{
			if ( count == textArray.length )
			{
				return;
			}
			
			textArray[ count ].visible = true;
			textArray[ count ].nameText.text = n;
			textArray[ count ].expText.text = "+ " + e;
			textArray[ count ].levelUp.visible = l;
			
			count++;
		}
		
		public function visibleItem():void
		{
			itemText.visible = true;
			itemText.text = "获得了:" + "\n";
			
			for ( var key:Object in itemObject )
			{
				itemText.appendText( itemObject[ key ].n + "*" + itemObject[ key ].i + "\n" );
			}
		}
		
		public function addItem( id:int , str:String ):void
		{
			if ( !itemObject[ id ] )
			{
				itemObject[ id ] = new Object();
				itemObject[ id ].i = 0;
				itemObject[ id ].n = str;
			}
			
			itemObject[ id ].i++;
		}
		
	}
	
}
